package top.boking.server;

import com.corundumstudio.socketio.SocketIOServer;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import top.boking.server.socket.SocketIOEventHandler;

@SpringBootApplication
public class Application implements CommandLineRunner {
    private final SocketIOServer server;
    private final SocketIOEventHandler eventHandler;

    public Application(SocketIOServer server, SocketIOEventHandler eventHandler) {
        this.server = server;
        this.eventHandler = eventHandler;
    }

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        // 注册事件处理器
        server.addListeners(eventHandler);
        System.out.println("正在启动 SocketIO 服务器...");
        server.start();
        System.out.println("SocketIO 服务器已启动在端口: " + server.getConfiguration().getPort());
    }
}
